package com.sweet.fourtimeoa.controller;

import com.sweet.fourtimeoa.pojo.dto.PageDto;
import com.sweet.fourtimeoa.pojo.entity.VehicleManagement;
import com.sweet.fourtimeoa.pojo.entity.VehicleUsage;
import com.sweet.fourtimeoa.pojo.vo.PageVo;
import com.sweet.fourtimeoa.service.CarService;
import com.sweet.fourtimeoa.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "用车管理")
@RestController
@RequestMapping("/oa/cars")
@CrossOrigin(origins = "*")
public class CarController {

    @Autowired
    private CarService carService;
    //分页获取所有的车辆信息
    @PostMapping("/getAllCar")
    @Operation(summary = "获取所有的车辆信息")
    public Result getAllCar(@RequestBody PageDto pageDto){
       PageVo<VehicleManagement> pageVo = carService.getAllCar(pageDto);
        return Result.success(pageVo);
    }
    //根据id删除车辆信息
    @DeleteMapping("/deleteCar/{carId}")
    @Operation(summary = "根据id删除车辆信息")
    public Result deleteCar(@PathVariable Integer carId){
        carService.deleteCarById(carId);
        return Result.success();
    }

    //根据id 查询数据
    @GetMapping("/getCarById/{carId}")
    @Operation(summary = "根据id查询数据")
    public Result getCarById(@PathVariable Integer carId){
        VehicleManagement vehicleManagement = carService.getCarById(carId);
        return Result.success(vehicleManagement);
    }

    //修改 车辆信息
    @PutMapping("/updateCar")
    @Operation(summary = "修改车辆信息")
    public Result updateCar(@RequestBody VehicleManagement vehicleManagement){
        carService.updateCar(vehicleManagement);
        return Result.success();
    }

    //新增
    @PostMapping("/saveCar")
    @Operation(summary = "新增车辆信息")
    public Result addCar(@RequestBody VehicleManagement vehicleManagement){
        carService.saveCar(vehicleManagement);
        return Result.success();
    }

    //用车申请
       @PostMapping("/saveCarManage")
       @Operation(summary = "用车申请")
    public Result saveCarManage(@RequestBody VehicleUsage VehicleUsage){
        carService.saveCarManage(VehicleUsage);
        return Result.success();
    }

    // 获取所有车辆id
    @GetMapping("/getAllCars")
    @Operation(summary = "获取所有车辆id")
    public Result getAllCarId(){
        return Result.success(carService.getAllCarId());
    }
}
